package com.my.framework.web.mvc.handler;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.http.converter.ByteArrayHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter;
import org.springframework.http.converter.xml.SourceHttpMessageConverter;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter;
import org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod;

import com.my.framework.web.mvc.controller.BaseController;
import com.my.toolkit.JsonUtil;
import com.my.utils.ClassUtil;

public class BaseControllerHandlerAdapter extends RequestMappingHandlerAdapter {
	public static final Logger log = LoggerFactory.getLogger(BaseControllerHandlerAdapter.class);

	private JsonUtil jsonUtil;
	
	
	public BaseControllerHandlerAdapter(JsonUtil jsonUtil) {
		this.jsonUtil=jsonUtil;
	}
	
	
	protected ServletInvocableHandlerMethod createInvocableHandlerMethod(HandlerMethod handlerMethod) {
		return new BaseControllerMethodHander(handlerMethod, jsonUtil);
	}
	
	protected  boolean supportsInternal(HandlerMethod handlerMethod) {
		Class clz=handlerMethod.getMethod().getDeclaringClass();
		return ClassUtil.isInstance(clz, BaseController.class);
	}
}